package com.zzq.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.zzq.annotation.EnableMyPage;
import com.zzq.domain.dto.SmileShootAddressDTO;
import com.zzq.domain.entity.SmileFee;
import com.zzq.domain.entity.SmilePhotographer;
import com.zzq.domain.entity.SmileShootAddress;
import com.zzq.domain.search.ShootAddressSearchParamet;
import com.zzq.enumerate.AuditEnum;
import com.zzq.result.SmileResult;
import com.zzq.service.ShootAdressAdminService;
import com.zzq.service.SmileFeeService;
import com.zzq.service.SmileShootAddressService;
import com.zzq.util.BeanCopyUtils;
import com.zzq.util.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
public class ShootAdressAdminServiceImpl implements ShootAdressAdminService {

    @Autowired
    SmileShootAddressService shootAddressService;
    @Autowired
    SmileFeeService feeService;

    @Override
    @EnableMyPage
    public SmileResult getShootAdresslist(ShootAddressSearchParamet searchParamet) {
        searchParamet.setFilterAudit(true);
        List<SmileShootAddressDTO> shootAddressDTOs = shootAddressService.getShootAddressDTO(searchParamet);
        return SmileResult.sucess("查询成功",shootAddressDTOs);
    }

    @Override
    public SmileResult updataShootAdress(SmileShootAddress address) {

        return null;
    }

    @Override
    @Transactional
    public SmileResult delShootAdressById(Long shootAddressId) {
        shootAddressService.removeById(shootAddressId);
        return SmileResult.sucess("删除成功");
    }

    @Override
    public SmileResult setAudit(Long ShootAddressId, Boolean isby) {
        LambdaUpdateWrapper<SmileShootAddress> queryWrapper = new LambdaUpdateWrapper();
        queryWrapper.eq(
                !ObjectUtils.isEmpty(ShootAddressId),
                SmileShootAddress::getId,
                ShootAddressId);
        if (isby) {
            queryWrapper.set(SmileShootAddress::getAudit, AuditEnum.AUDITED.getName());
        } else {
            queryWrapper.set(SmileShootAddress::getAudit, AuditEnum.NOAUDITED.getName());
        }
        shootAddressService.update(queryWrapper);
        return SmileResult.sucess("审核成功");
    }

    @Override
    public SmileResult addHotAdress(SmileShootAddressDTO shootAddress) {
        shootAddress.setShootHot(1);
        SmileFee smileFee = shootAddress.getSmileFee();
        SmileShootAddress smileShootAddress = BeanCopyUtils.copyBean(shootAddress, SmileShootAddress.class);
        shootAddressService.save(smileShootAddress);
        smileFee.setId(smileShootAddress.getId());
        feeService.save(smileFee);
        return SmileResult.sucess("添加成功");
    }

    @Override
    public SmileResult setAdressFee(SmileFee smileFee) {
        return null;
    }

}
